package com.yulongtian.offers.day202209.day20220922;

/**
 * https://leetcode.cn/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof/?plan=lcof&plan_progress=g8d07hi
 *
 * @author YulongTian
 * @date 2022/9/22 - 10:03
 */
public class Test01 {
    public static void main(String[] args) {
        System.out.println(translateNum(419605557));
    }

    public static int translateNum(int num) {
        char[] chars = String.valueOf(num).toCharArray();
        int[] temp = new int[chars.length];
        temp[0] = 1;
        if (chars.length < 2) {
            return 1;
        }
        if (chars.length == 2) {
            if (chars[0] == '2' && chars[1] <= '5') {
                return 2;
            } else if (chars[0] == '2' && chars[1] > '5') {
                return 1;
            } else if (chars[0] == '1' && chars[1] <= '5') {
                return 2;
            } else if (chars[0] == '1' && chars[1] > '5') {
                return 2;
            } else {
                return 1;
            }
        }
        if (chars[0] == '2' && chars[1] <= '5') {
            temp[1] = 2;
        } else if (chars[0] == '2' && chars[1] > '5') {
            temp[1] = 1;
        } else if (chars[0] == '1' && chars[1] <= '5') {
            temp[1] = 2;
        } else if (chars[0] == '1' && chars[1] > '5') {
            temp[1] = 2;
        } else {
            temp[1] = 1;
        }

        for (int i = 2; i < chars.length; i++) {
            if (chars[i - 1] != '0' && chars[i - 1] == '2' && chars[i] <= '5') {
                temp[i] = temp[i - 1] + temp[i - 2];
            }else if(chars[i - 1] != '0' && chars[i - 1] == '1'){
                temp[i] = temp[i - 1] + temp[i - 2];
            }
            else{
                temp[i] = temp[i - 1];
            }
        }


        return temp[chars.length - 1];
    }
}
